﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Abp.Modules;
using Abp.Reflection.Extensions;
using FwProject.Configuration;
using Newtonsoft.Json;
using Abp.BackgroundJobs;
using System;
using FwProject.Distribution;
using Abp.Runtime.Caching.Redis;
using Abp.Dependency;
using System.Threading;
using Abp.Hangfire.Configuration;
using Abp.Hangfire;
using Abp.Threading.BackgroundWorkers;
using FwProject.BackGround.DistributionEnter;

namespace FwProject.Web.ShopHost.Startup
{
    [DependsOn(
        typeof(FwProjectShopCoreWebCoreModule),
        typeof(AbpHangfireAspNetCoreModule),
        typeof(AbpRedisCacheModule)
        )]
    public class FwProjectWebHostModule: AbpModule
    {
        private readonly IHostingEnvironment _env;
        private readonly IConfigurationRoot _appConfiguration;

        public FwProjectWebHostModule(IHostingEnvironment env)
        {
            _env = env;
            _appConfiguration = env.GetAppConfiguration();
        }

        public override void Initialize()
        {

            IocManager.RegisterAssemblyByConvention(typeof(FwProjectWebHostModule).GetAssembly());
         
        }
        public override void PostInitialize()
        {
            var workManager = IocManager.Resolve<IBackgroundWorkerManager>();
            ///系统服务运行检查者系统监听服务已改到服务器服务中使用
            //workManager.Add(IocManager.Resolve<PublicSendWebProbeWorkBackGround>());
        }
        public override void PreInitialize()
        {
            Configuration.BackgroundJobs.UseHangfire();
            IocManager.Register<IBackgroundJobStore, BackgroundJobStore>();
            Configuration.Caching.UseRedis(options =>
            {
                options.ConnectionString = _appConfiguration["Abp:RedisCache:ConnectionString"];
                options.DatabaseId = _appConfiguration.GetValue<int>("Abp:RedisCache:DatabaseId");
            });

        }
    }
}
